<template>
   <view class="advice" >
      <ul>
        <li
          v-for="(advice,index) in searchResList"
          :key="index"
          @click="clickAdvice(advice)"
          >
          <i class="iconfont icon-sousuo" ></i>
          <view v-html="highlight(advice)" ></view>
        </li>
      </ul>
    </view>
</template>

<script>
export default {
  name: 'search-advice',
  props: {
    searchResList: {
      type: Array,
      required: true,
      default: () => { return [] }
    },
    keyword: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
    }
  },
  methods: {
    // 搜索关键词高亮显示
    highlight (str) {
      const highlightStr = `<span style="color:red">${this.keyword}</span>`
      return str.replace(new RegExp(this.keyword, 'gi'), highlightStr)
    },
    // 点击类型建议item 发请求查询文章
    clickAdvice (keyword) {
      console.log('点击类型建议item 发请求查询文章')
      this.$emit('onSearch', keyword)
      // this.searchResList = [] // 清空联想建议才能显示搜索结果
      // this.hotSearchResList.push(item)
      // this.keyword = item
      // this.getArticleList()
      // this.$emit('close')
    }
  }
}
</script>
<style lang="scss" scoped>
.advice {
  // box-shadow: 0 3px 5px 0px rgba(165, 177, 222, 0.5);
  // border-bottom: 1px solid #f1f1f2;
  view {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  ul {
    overflow: hidden;
    padding: 0;
    li {
      font-size:20px;
      line-height:30px;
      display: flex;
      align-items: center;
      justify-content: space-between;

    }
  }

}

.advice{
  border-bottom: none !important;
  li{
    display: flex !important;
    justify-content: flex-start !important;
    border-bottom: 1px solid rgb(243, 243, 243) !important;
    font-size: 16px !important;
    // margin:10px 0;
    padding:  10px 0px;
    .icon-sousuo{
      color: rgb(207, 200, 200);
      margin-right:5px;
      font-size: 22px;
    }
  }
}
</style>
